﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility; 

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RM

        public List<tb_RM> GetAllRM()
        {

            var query = (from obj in this.tb_RMs
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_RM GetRMById(int id)
        {
            return this.tb_RMs.SingleOrDefault(tb_RM => tb_RM.Id == id);
        }

        public List<tb_RM> GetRMByTypeId(int typeId)
        {
            var query = (from obj in this.tb_RMs
                         where obj.TypeId == typeId
                         select obj).ToList();
            return query;
        }


      
        public void CreateRM(tb_RM entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RMs.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyRM(tb_RM entity)
        {
            tb_RM instance = this.tb_RMs.SingleOrDefault(p => p.Id == entity.Id);

            instance.BelongVender = entity.BelongVender;
            instance.Code = entity.Code;
            instance.Count = entity.Count;
            instance.Description = entity.Description;
            instance.Price = entity.Id; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;
            instance.Name = entity.Name;

            this.SubmitChanges();
        }
        public void DeleteRM(tb_RM entity)
        {
            tb_RM deleteEntity = tb_RMs.SingleOrDefault(p => p.Id == entity.Id);
            tb_RMs.DeleteOnSubmit(deleteEntity);
            this.SubmitChanges();
        }

        #endregion

    }

}
